﻿using System;
using WickedFlame.Core.Shapes;

namespace WickedFlame.Core.State
{
    [Serializable]
    internal class RectangleMemento : ShapeMemento
    {
        double _x;
        double _y;
        double _width;
        double _height;
        double _cornerRadius;

        public override void SaveProperties(VectorShape shape)
        {
            base.SaveProperties(shape);

            var r = shape as RectangleShape;
            if (r != null)
            {
                _x = r.X;
                _y = r.Y;
                _width = r.Width;
                _height = r.Height;
                _cornerRadius = r.CornerRadius;
            }
        }

        public override void ResetProperties(VectorShape shape)
        {
            base.ResetProperties(shape);

            var r = shape as RectangleShape;
            if (r != null)
            {
                r.Rectangle = new System.Windows.Rect(_x, _y, _width, _height);
                r.CornerRadius = _cornerRadius;
            }
        }

        public override VectorShape GenerateShape()
        {
            var shape = new RectangleShape();
            shape.ResetState(this);

            return shape;
        }
    }
}
